﻿Imports Publics
Imports DevExpress.XtraReports.UI
Imports System.Windows.Forms

Public Class FrmBaoCaoCongNoSieuThi

    Private Sub FrmHDBanLe_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

    End Sub

    Private Sub FrmBaoCaoCongNoSieuThi_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If e.KeyChar = Chr(Keys.Enter) Then
            SendKeys.Send("{tab}")
        End If
    End Sub

    Private Sub FrmHDBanLe_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        dteDenNgay.DateTime = Now
        dteTuNgay.DateTime = Now
    End Sub

    Private Sub btnTroGiup_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnTroGiup.ItemClick

    End Sub

    Private Sub btnDong_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnDong.ItemClick
        Me.Close()
    End Sub

    Private Sub btnChon_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnTinhToan.ItemClick
        Dim lst = dbTV.Func_ST_BaoCaoTongHopCongNo(dteTuNgay.DateTime, dteDenNgay.DateTime).ToList
        grdBaoCaoTHCongNo.DataSource = (From ds In lst Join kh In lstSourceAllKhachHang On ds.IDKhachHang Equals kh.ID _
                                        Order By kh.MaKhachHang _
                                        Select kh.MaKhachHang, kh.TenKhachHang, kh.DiaChi, ds.SoPhaiThuDauKy, ds.SoPhaiTraDauKy, _
                                        ds.PhatSinhPhaiThu, ds.PhatSinhPhaiTra, ds.SoPhaiThuCuoiKy, ds.SoPhaiTraCuoiKy).ToList
        grdBaoCaoTHCongNo.RefreshDataSource()
    End Sub


    Private Sub grvHDBanLe_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If grvBaoCaoTHCongNo.FocusedRowHandle = 0 AndAlso e.KeyCode = Windows.Forms.Keys.Up Then
            grvBaoCaoTHCongNo.FocusedRowHandle = DevExpress.XtraGrid.GridControl.AutoFilterRowHandle
        End If
        If e.Control AndAlso e.KeyCode = Keys.C Then
            e.Handled = SetClipboardValueCellFocusInGrid(grvBaoCaoTHCongNo)
        End If
    End Sub

    Private Sub btnXuatDuLieu_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
        ExportExcel(grdBaoCaoTHCongNo)
    End Sub


    Private Sub grvChiTiet_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        If e.Control AndAlso e.KeyCode = Keys.C Then
            e.Handled = SetClipboardValueCellFocusInGrid(grvBaoCaoTHCongNo)
        End If
    End Sub

    Private Sub btnXuatDL_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnXuatDL.ItemClick
        Export_Dialog(SaveFileDialog1, grdBaoCaoTHCongNo)
    End Sub

    Private Sub btnInBaoCao_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnInBaoCao.ItemClick
        Dim rpt As New rptCongNoTongHopSieuThi
        Dim pathReportPhatHanh As String = ""
        Dim strPath As String = pathReportPhatHanh & "\\" & "rptCongNoTongHopSieuThi.repx"
        Try
            rpt = DevExpress.XtraReports.UI.XtraReport.FromFile(strPath, True)
        Catch ex As Exception
            rpt = New rptCongNoTongHopSieuThi
        End Try
        rpt.TuNgay = dteTuNgay.DateTime
        rpt.DenNgay = dteDenNgay.DateTime
        rpt.BinSource.DataSource = grdBaoCaoTHCongNo.DataSource
        SaveLog("Sổ tổng hợp công nợ siêu thị", "Xem báo cáo tổng hợp công nợ", "Xem báo cáo")
        Dim frm As New FrmCustomReport(rpt, strPath, FrmCustomReport.CongNoTongHopSieuThi)
        frm.WindowState = FormWindowState.Maximized
        frm.ShowDialog()
    End Sub
End Class
